package org.example.versii.channel.impl;

import org.example.versii.channel.IChannel;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author mojito
 * @Classname ChannelFactory
 * @Description TODO
 * @Date 2020/7/22 下午10:00
 **/
@Component("channelFactory")
public class ChannelFactory implements ApplicationContextAware {

    private NettyChannel nettyChannel;
    private Map<String, IChannel> channelMap;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        Map<String, IChannel> beans = applicationContext.getBeansOfType(IChannel.class);
        channelMap = beans;
    }

    public IChannel getChannel(String type) {
        return channelMap.get(type);
    }
}
